<?php

namespace services;

require_once ROOT_SERVICES_MODEL . DS . 'warehouse.php';
require_once ROOT_SERVICES . DS . 'oms_shipping.php';

use services\models as models;

class service_interface {

    private static $_db;
    private static $_cache;
    private static $_init_resource = FALSE;

    public static function set_resource($db, $cache) {
        self::$_cache = $cache;
        self::$_db = $db;
        self::$_init_resource = TRUE;
    }

    public static function get_stock($sku) {
        try {
            if (self::$_init_resource) {
                $warehouse = new models\warehouse(self::$_db, self::$_cache);
                $stock = $warehouse->get_stock($sku);
                return array('result' => 'ok', 'data' => $stock['STOCK']);
            }
        } catch (\PDOException $pe) {
            return array('result' => 'error', 'data' => $pe->getMessage());
        } catch (Exception $e) {
            return array('result' => 'error', 'data' => $e->getMessage());
        }
    }

    public static function get_status_shipping($sku) {
        try {
            if (self::$_init_resource) {
                $oms_shipping = new oms_shipping(self::$_db, self::$_cache);
                $result = $oms_shipping->get_shipment_provider_status(0);
                return array('result' => 'ok', 'data' => $result);
            }
        } catch (\PDOException $pe) {
            return array('result' => 'error', 'data' => $pe->getMessage());
        } catch (Exception $e) {
            return array('result' => 'error', 'data' => $e->getMessage());
        }
    }

}

?>
